<?php
define("NO_LOGIN",1);
require("global.php");
if($phprpg->input['submit']){
	if(!preg_match("/^[-_a-zA-Z0-9]+$/", $phprpg->input['username'])){
		$error[] = "Invalid username/password";
	}
	if(!isset($error)){
		$checkUser = $db->select("players","*","username='".$phprpg->input['username']."'");
		if($db->recordcount($checkUser) != 1){
			$error[] = "Invalid username/password";
		}else{
			$u = $db->fetchrow($checkUser);
			$pass = sha1(md5($phprpg->input['password']).md5($u['salt']));
			if($pass == $u['password']){
				$hash = md5(md5($u['pid']).md5($phprpg->getIP()).md5($cfg['login']['hash']));
				if($phprpg->input['rememberme'] == 1){
					$type = 2;
				}else{
					$type = 1;
				}
				$phprpg->addSession('uid', $u['pid'], $type);
				$phprpg->addSession('hash', $hash, $type);
				header("location: index.php");
			}else{
				$error[] = "Invalid username/password";
			}
		}
	}
	if(isset($error)){
		$errors = $phprpg->inline_error($error);
	}
}
eval("\$login = \"".$templates->get("login")."\";");
$templates->output($login);
?>